//
//  BrokeViewController.m
//  LiveDailyNews
//
//  Created by smu on 11-7-25.
//  Copyright 2011年 duk. All rights reserved.
//

#import "BrokeViewController.h"
#import "PostPicViewController.h"


@implementation BrokeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tabBarItem.title = @"爆料";
		self.tabBarItem.image = [UIImage imageNamed:@"TAB_ICON_MENU.png"];
        
        //导航栏添加内容
        //左边logo
        UIImage *logoImage = [[UIImage alloc] initWithContentsOfFile:[
                                                                      [[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Logo.png"]];
        UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 32)];  
        logoImageView.image = logoImage;
        [logoImage release];
        UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:logoImageView]; 
        [logoImageView release];
        self.navigationItem.leftBarButtonItem = leftBarButton;
        [leftBarButton release];
        
        //中间标题
        self.navigationItem.title = @"爆料内容";
        
        //右边爆料按钮按钮
        UIBarButtonItem *brokeButton = [[UIBarButtonItem alloc]
                                       initWithTitle:@"爆料"
                                       style:UIBarButtonItemStyleBordered
                                       target:self 
                                       action:@selector(brokeClick)];
        self.navigationItem.rightBarButtonItem = brokeButton;
    }
    return self;
}

//爆料
- (void)brokeClick
{
    PostPicViewController *postPicViewController = [[PostPicViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:postPicViewController animated:YES];
    self.hidesBottomBarWhenPushed = NO;

}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    //test tableView
    listData = [[NSArray alloc] initWithObjects:@"爆料内容是非得失史蒂夫士大夫撒旦法",@"爽肤水打发大师傅是大幅度是", nil];
    listPic = [[NSArray alloc] initWithObjects:@"Default.png",@"Default.png", nil];
    
    //获取整个手机屏幕
    UIView *contentView = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame] autorelease];
	
	contentView.autoresizesSubviews = YES;
	self.view = contentView;
	[self.view setBackgroundColor:[UIColor clearColor]];

    
    brokeTableView = [[UITableView alloc] initWithFrame:
                  CGRectMake(0, 25, contentView.bounds.size.width, contentView.bounds.size.height - 44 - 48) style:UITableViewCellStyleDefault];
	brokeTableView.delegate = self;
	brokeTableView.dataSource = self;
	brokeTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
	brokeTableView.scrollEnabled = YES;
	[brokeTableView setBackgroundColor:[UIColor clearColor]];
    
	[self.view addSubview:brokeTableView];
    
    
    
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [listData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *brokeTableIdentifer = @"BrokeTableIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:brokeTableIdentifer];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                 reuseIdentifier:brokeTableIdentifer] autorelease];
    }
    NSUInteger row = [indexPath row];
    //test
    UIImage *bimage = [[UIImage alloc] initWithContentsOfFile:
                         [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[listPic objectAtIndex:row]]];    

    
    cell.textLabel.text =[listData objectAtIndex:row];
    cell.imageView.image = bimage;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}


@end
